<?php 
namespace Admin\Model;
use Think\Model;
class DetailModel extends Model{
	public function saveFile($post,$file,$thumb){
		if(!$file['error']){
			$cfg=array(
				'rootPath'=>WORKING_PATH . UPLOAD_ROOT_PATH
			);
			$upload=new \Think\Upload($cfg);
			$info=$upload->uploadOne($file);
			if($info){
				$post['filepath']=UPLOAD_ROOT_PATH . $info['savepath'] . $info['savename'];
				$post['filename']=$info['name'];
				$post['hasfile']=1;
			}
		}
		if(!$thumb['error']){
			$cfg=array('rootPath'=>WORKING_PATH . UPLOAD_ROOT_PATH);
			$upload=new \Think\Upload($cfg);
			$info=$upload->uploadOne($thumb);
			if($info){
				$post['picture']=UPLOAD_ROOT_PATH . $info['savepath'] . $info['savename'];
				$image=new \Think\Image();
				$image->open(WORKING_PATH . $post['picture']);
				$image->thumb(100,100);
				$image->save(WORKING_PATH . UPLOAD_ROOT_PATH . $info['savepath'] . 'thumb_' . $info['savename']);
				$post['thumb']=UPLOAD_ROOT_PATH . $info['savepath'] . 'thumb_' . $info['savename'];
			}

		}
		$post['addtime']=time();
		//dump($post);die;
		if($post['id']){
			return $this->save($post);
		}else{
			return $this->add($post);
		}
		
	}
}
 ?>